package com.dnb.webmash.playmaker.client.ui;

import com.dnb.webmash.playmaker.client.mediaplayer.MediaPlayersManager;
import com.dnb.webmash.playmaker.shared.PlayerType;
import com.dnb.webmash.playmaker.shared.PlaylistItem;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

public class AddMediaTab extends Composite {
	public AddMediaTab(){
		/* START OF ADD MEDIA TAB
		 */
		
		DockLayoutPanel tab5_addmediapanel = new DockLayoutPanel(Unit.EM);
		
		//THE TEST PLAYER INIT... (added near the end of this tab)
		final MediaPlayersManager testPlayer = new MediaPlayersManager();
		testPlayer.setSize("100%", "100%");

		final RichTextArea embedCodeTextArea = new RichTextArea();
		embedCodeTextArea.setStyleName("gwt-EmbedCodeRichTextArea");
		embedCodeTextArea.setSize("75%", "100%");
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		tab5_addmediapanel.addNorth(horizontalPanel, 2.0);
		
		final Button button = new Button("Test");
		horizontalPanel.add(button);
		
		button.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				//grab the text from the embed-box
				String txt = embedCodeTextArea.getText();
				//TODO verify it isnt malicious
				//then create media item
				PlaylistItem f = new PlaylistItem("PlaylistItemToTest");
				f.setElement(txt);					  
				f.setPlayerType(PlayerType.EMBED);
				f.setPlayable(true);
				//and load it on the test player
				testPlayer.embedItem(f);
			}
		});
		
		VerticalPanel addMediaVerticalPanCentre = new VerticalPanel();
		tab5_addmediapanel.add(addMediaVerticalPanCentre);
		addMediaVerticalPanCentre.setSize("100%", "100%");
		addMediaVerticalPanCentre.add(embedCodeTextArea);
		addMediaVerticalPanCentre.add(testPlayer);
		
		this.initWidget(tab5_addmediapanel);
		/* END OF ADD MEDIA TAB
		 * 
		 */
	}
	@Override
	public void setWidth(String width) {//TODO add to prefs
		super.setWidth(width);
	}
	@Override
	public void setHeight(String height) {
		super.setHeight(height);
	}
}